/**
 * 
 */
package pl.prv.polanie.client.panels.widgets;

import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Janusz Prokulewicz
 * Created: Jan 9, 2009
 */
public class SelectableVerticalPanel extends VerticalPanel {
	
	private static final String STYLE_SELECTABLE_VERTICAL_PANEL = "my-SelectableVerticalPanel-highlightedWidget";

	private int highlightedWidgetIndex = -1;

	
	
	
	public void highlightPreviousWidget() {
		
		if (highlightedWidgetIndex == 0) {
			highlightedWidgetIndex = -1;

			Widget w = getWidget(0);
			w.removeStyleName(STYLE_SELECTABLE_VERTICAL_PANEL);
			runOnLosingHighlightingOnWidget();
		} else if (highlightedWidgetIndex > 0) {
			Widget w = getWidget(highlightedWidgetIndex);
			w.removeStyleName(STYLE_SELECTABLE_VERTICAL_PANEL);
			
			highlightedWidgetIndex--;
			
			w = getWidget(highlightedWidgetIndex);
			w.addStyleName(STYLE_SELECTABLE_VERTICAL_PANEL);
		}
	}
	
	
	public void highlightNextWidget() {
		//brak zmiany podswietlenia
		if (highlightedWidgetIndex == getWidgetCount()-1) {
			return;
		}
		
		
		if (highlightedWidgetIndex == -1) {
			highlightedWidgetIndex = 0;
			
			Widget w = getWidget(0);
			w.addStyleName(STYLE_SELECTABLE_VERTICAL_PANEL);
		} else {
			Widget w = getWidget(highlightedWidgetIndex);
			w.removeStyleName(STYLE_SELECTABLE_VERTICAL_PANEL);
			
			highlightedWidgetIndex++;
			
			w = getWidget(highlightedWidgetIndex);
			w.addStyleName(STYLE_SELECTABLE_VERTICAL_PANEL);
		}
		runOnHighlightingOnWidget();
	}
	
	
	public Widget getHighlightedWidget() {
		if (highlightedWidgetIndex == -1) return null;
		return getWidget(highlightedWidgetIndex);
	}
	
	protected void runOnLosingHighlightingOnWidget() {}
	
	protected void runOnHighlightingOnWidget() {}
}
